package com.kotlin.tsw.baselibrary.widgets

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.AnimationDrawable
import android.util.Log
import android.view.Gravity
import android.widget.ImageView
import com.kotlin.tsw.baselibrary.R
import org.jetbrains.anko.find

class ProgressLoading private constructor(context: Context,theme:Int ):Dialog(context,theme) {
    companion object {
        private var animDrawable:AnimationDrawable?=null
        private lateinit var  mDialog :ProgressLoading
        fun create(context: Context):ProgressLoading{
            mDialog= ProgressLoading(context, R.style.LightProgressDialog)
            mDialog.setContentView(R.layout.progress_dialog)
            mDialog.setCancelable(true)
            mDialog.setCanceledOnTouchOutside(false)
            mDialog.window.attributes.gravity=Gravity.CENTER
            val lp=mDialog.window.attributes
            lp.dimAmount=0.2f
            mDialog.window.attributes=lp
            val loadingView = mDialog.find<ImageView>(R.id.iv_loading)
            animDrawable = loadingView.background as AnimationDrawable
            return mDialog
        }
    }
    fun showLoading(){
        super.show()
        animDrawable?.start()
    }
    fun hideLoading(){
        super.hide()
        animDrawable?.stop()
    }
}